import axios from "axios";

const instance = axios.create({
    baseURL: '/sso',
    timeout: 10000
})

// request interceptor
instance.interceptors.request.use(config => {
    // Add authorization header
    const token = localStorage.getItem('satoken')
    if (token != null && token.length > 0) {
        config.headers['satoken'] = 'Bearer ' + token;
    }
    return config;
}, error => {
    return Promise.reject(error);
});

// response interceptor
instance.interceptors.response.use(response => {
    return response.data;
}, error => {
    return Promise.reject(error.response);
});

export default instance;